package me.tuyou.activiti.xmlParse;

import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.*;
import org.activiti.bpmn.model.Process;
import org.activiti.engine.impl.util.io.InputStreamSource;
import org.activiti.engine.impl.util.io.StreamSource;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class extensionElementsTest {

    public static void main(String[] args) throws IOException {
        ClassPathResource resource = new ClassPathResource("ExtensionElementsTest.bpmn");
        StreamSource source = new InputStreamSource(resource.getInputStream());
        BpmnXMLConverter converter = new BpmnXMLConverter();
        BpmnModel bpmnModel = converter.convertToBpmnModel(source, false, false, "utf-8");
        Process leave = bpmnModel.getProcesses().get(0);
        FlowElement flowElement = leave.getFlowElement("_3");
        Map<String, List<ExtensionElement>> extensionElements = flowElement.getExtensionElements();
        print(extensionElements);
    }

    public static void print(Map<String, List<ExtensionElement>> extensionElements) {
        for (String s : extensionElements.keySet()) {
            System.out.println(s);
            List<ExtensionElement> extensionElementList = extensionElements.get(s);
            for (ExtensionElement extensionElement : extensionElementList) {
                print(extensionElement.getChildElements());
            }
        }
    }
}
